<template>
  <div id="blog-category">
    <h2>分类</h2>
    <p>目前共{{categories.length}}种分类！</p>
    <ul v-for="category in categories">
      <li @click="categoryClick(category)">{{category}}</li>
    </ul>
    <div style="clear: both" />
  </div>
</template>

<script>
import {getCategories} from "@/network/blogRequest";

export default {
  name: "CategoryList",
  data() {
    return {
      categories: []
    }
  },
  methods: {
    /*网络请求*/
    getCategories() {
      getCategories().then(res => {
        this.categories = res.data;
      })
    },

    /*事件监听*/
    categoryClick(category) {
      this.$router.push("/blog/category/" + category)
    }
  },
  created() {
    this.getCategories();
  }
}
</script>

<style scoped>
  ul {
    list-style: none;
  }

  #blog-category {
    width: 620px;
    padding: 20px 30px;
    text-align: center;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid #d5d5d5;
    box-shadow: 5px 5px 5px 0 rgba(0, 0, 0, 0.3);
  }

  #blog-category p {
    margin: 20px 0 20px 0;
  }

  #blog-category ul li {
    float: left;
    width: 150px;
    height: 80px;
    line-height: 80px;
    text-align: center;
    color: white;
    background-color: #999999;
    margin: 5px 0 0 5px;
  }

  #blog-category ul li:hover {
    background-color: darkgrey;
    cursor: pointer;
  }
</style>